<template>
    <el-card shadow="never" style="max-height: 70vh; overflow: auto">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
            <el-row>
                <el-col :span="24" v-if="form.tenant_id && form.platform === 'px'">
                    <el-form-item label="培训平台讲师:" prop="lecturer_id">
                        <SelectPage v-model="form.lecturer_id" :url="'/admin/px.lecturer/selectPage'"
                                    placeholder="请选择培训平台讲师，机构和社区不选"
                                    :filter="{'qu_px_lecturer.tenant_id':{value:form.tenant_id,op:'='}}"
                                    show_field="name" show_id="id" query_field="id" :multiple="false" />
                        <div class="tip-info">选择培训平台讲师，机构和社区不选</div>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="回放天数:" prop="transcribe_day">
                        <el-input-number :min="0" v-model="form.transcribe_day" placeholder='请输入回放天数'/>
                        <div class="tip-info">0为直播回放，永久有效</div>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item>
                <el-button type="primary" @click="submitForm">确认</el-button>
                <el-button type="warning" @click="cancel">取消</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>
<script>
export default {
    name: 'EditFormSetting',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            pickerOption: {
                // 设置禁用状态，参数为当前日期，要求返回 Boolean
                disabledDate: (time) => {
                    let date = new Date().getTime();
                    return time.getTime() < date;
                },
            },
            // 编辑表单验证规则
            rules: {
                transcribe_day: [{required: true, message: '请输入回放天数', trigger: 'blur'}],
                fuli: [{required: true, message: '请输入直播福利', trigger: 'blur'}],
            },
            form: {},
            lecturerList: []
        }
    },
    watch: {
        findFormData: {
            handler(nval) {
                if (JSON.stringify(nval) !== '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                } else {
                    this.$set(this, 'form', {})
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },
        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },
        // 表单重置
        reset() {
            this.resetForm('form')
        },
    }
}
</script>
<style scoped lang="scss">
.tip-info {
    color: #888888;
    margin-top: 2px;
}
</style>
